var path = require('path');
var qiniu = require('./libs/qiniuop');

var args = process.argv;

if (args && args[2]) {
    //upyun.uploadFile('/test/', "ubuntu-essential.tar", "./ubuntu-essential.tar", "application/octet-stream", function() {
    //    console.log('ok')
    //}, function() {
    //    console.log('err')
    //});

    var tasks = Array.prototype.slice.call(args, 2);

    (function nextTask() {
        var task = tasks.shift();

        if (!task) return;

        if (!path.isAbsolute(task)) {
            task = path.resolve(task);
        }

        var filename = path.basename(task);

        qiniu.uploadFile(task, filename, function() {
            console.log(filename + "上传成功");
            nextTask();
        }, function() {
            console.log(filename + "上传失败");
            nextTask();
        }, true);
        //console.log(task)
        //nextTask();
    })();
}